package com.chenbei.common.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenbei.common.domain.vo.Pagination;
import com.chenbei.common.enums.ResponseResultEnum;
import com.chenbei.common.domain.vo.ApiResponse;

//响应结果工具类
public class ApiResponseUtil {

    public static ApiResponse<Object> success() {
        return new ApiResponse<>(ResponseResultEnum.SUCCESS.getCode(), ResponseResultEnum.SUCCESS.getMessage(), null);
    }

    public static <T> ApiResponse<Pagination<T>> success(Page<T> page) {
        Pagination<T> pagination = new Pagination<>();
        pagination.setTotal(page.getTotal());
        pagination.setData(page.getRecords());

        return success(pagination);
    }

    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(ResponseResultEnum.SUCCESS.getCode(), ResponseResultEnum.SUCCESS.getMessage(), data);
    }

    public static ApiResponse<Object> fail(ResponseResultEnum responseResultEnum) {
        return new ApiResponse<>(responseResultEnum.getCode(), responseResultEnum.getMessage(), null);
    }

    public static ApiResponse<Object> fail(ResponseResultEnum responseResultEnum, String message) {
        return new ApiResponse<>(responseResultEnum.getCode(), message, null);
    }
}
